﻿--Logs / Stats of Execution


WITH STARTS ([ExecGuid], [Date])
AS
(
	SELECT DISTINCT [ExecGuid], [Date]
	FROM Config..VROOM_LOG (NOLOCK) 
	WHERE Logger='DataLoader.LoaderBootstrap' AND MESSAGE = 'Starting...'
),
STOPS ([ExecGuid], [Date])
AS
(
	SELECT DISTINCT [ExecGuid] , [Date]
	FROM Config..VROOM_LOG (NOLOCK) 
	WHERE Logger='DataLoader.LoaderBootstrap' AND MESSAGE = 'Stopping...'
)

SELECT
	STOPS.ExecGuid, STARTS.Date, STOPS.Date, DATEDIFF(s, STARTS.Date, STOPS.Date) AS [TimeInMinutes]
FROM 
	STARTS
	INNER JOIN STOPS  ON STOPS.ExecGuid  = STARTS.ExecGuid
ORDER BY
	STOPS.Date DESC

/*
SELECT * FROM Config..VROOM_LOG (NOLOCK) ORDER BY 1 DESC
*/
/*

TRUNCATE TABLE Config..VROOM_LOG
TRUNCATE TABLE Config..AuditLog

---TRUNCAET Staging tables----Run as Block-------------------------
USE Staging
GO
EXEC sp_MSForEachTable 'TRUNCATE TABLE ?'
---TRUNCAET Staging tables----Run as Block-------------------------

*/